<h1>รายงานสรุปความต้องการใช้งานวัสดุ-ครุภัณฑ์</h1>
 <?php 
if(!isset($_POST["ids"])){ echo "Error: คุณไม่ได้เลือกรายการใดๆ"; exit;  }
$ids = implode(",", $_POST["ids"]);
$rows = $this->db->query("select * from meterial_base_categories order by sort_order asc")->result_array();
foreach($rows as $base){
$sql ="SELECT 
	request_item_views.category_id,
	request_item_views.category_name, 
	sum(request_item_views.amount) as amount,
	mr_id
FROM request_item_views where mr_id in ($ids)  and   cat_base_id = ".$base['cat_base_id'] ."  GROUP BY category_name" ;
$cats =  $this->db->query($sql)->result_array();
if(count($cats)){
?>

<table class="list" style="width:100%" >
          <tbody><tr class=" odd">
            <th style="width:500px;" ><?php echo $base["cat_base_name"]; ?></th>
            
           
             <th class="ct" style="width:70px;">จำนวน</th>
          </tr>
         <?php
          $i = 1;
          foreach($cats as $row){ ?>
        
          <tr class="<?php if($i++%2){ echo "even";} ?>" >
            
            
            <td><?php echo $row['category_name']; ?>
          <div style="color:#999;">
            <?php 
            $sql = "select * from request_item_views where category_id =".$row["category_id"];
            $subs = $this->db->query($sql)->result_array(); 
           
            foreach($subs as $sub)
            {
            	
            	echo " [".$sub["firstname"]." ".$sub["lastname"]."] จำนวน ".$sub["amount"]."<br/> " ;
            }
           
            //print_r($subs);
            ?>
             </div>
            </td>
            
            <td class="ct" ><?php echo $row['amount']; ?></td>
            
          </tr>
          <?php } } ?>
        </tbody></table>
<?php } ?>
